<?php
// Returns an XML list of all admitted students with their full name and 
// primary key (id).

session_start();
if ( ! isset( $_SESSION['adminLoggedIn'] ) ) {
   exit;
}

require_once("db.php");

$sql = "
   SELECT id as primaryKey,
      concat( lastname, ', ', firstname ) AS fullname
   FROM `gs_students`
   ORDER BY fullname
";

$result = my_mysql_query($sql);

// Output the result as XML.
echo "<students>\n";
while ($row = mysql_fetch_assoc($result)) {
   echo "<student>\n";
   foreach (array_keys($row) as $key) {
      echo "<$key>"; echo $row[$key]; echo "</$key>\n";
   }
   echo "</student>\n";
}
echo "</students>\n";

?>